home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Pocket 6.3 / Pocket DA / Manual Addendum next >
Text File  |  1993-07-04  |  10KB  |  145 lines

  1. Pocket Forth desk accessory version 1.6.3      4 July 1993
  2.  
  3. The Pocket Forth desk accessory, version 1.6.3, is provided for the convenience of users of system 6 and earlier. All of the features of 1.5 are preserved and some features of the release 6.2 application are added. This document adds to the manual.
  4.  
  5. New features (from 0.6.2 and 0.6.3) included in this version:
  6.     floating point numbers
  7.     ,S and ?GESTALT
  8.     INTERPRET
  9.     \
  10.     DEPTH
  11.     WARM
  12.  
  13. The word GROW is also included allowing a very small dictionary to be used. The initial size is 32K bytes 
  14.  
  15. The following features of version 0.6 are not included because they are are based on Apple Events and are not used by desk accessories:
  16.     AE:  and  ;AE
  17.     WARM
  18.     BYE
  19.     drag & drop programming
  20.  
  21. Some of the actions of the desk accessory are different than those of the application. The following sections explain the differences.
  22.  
  23. Machine Language
  24.  
  25. The registers D4 and D5 are used to store important information about the system. Preserve their contents if you use them.
  26.  
  27. Events
  28.  
  29. The desk accessory has three additional variables in the +MD table:
  30.    _name_      _address_ 
  31.     MyID           30 +md
  32.     Keydown     32 +md
  33.     Cursor        34 +md
  34.  
  35. • MyID contains the resource ID of the DICT and other owned resources.  See the resource section.
  36.  
  37. • Keydown is a handler that executes when a key is pressed.  It contains the text interpreter, so change it carefully if you want to return to Forth.  See the turnkey section.
  38.  
  39. • Cursor executes periodically like Idle.  It should be used for changing the cursor shape if necessary.  By default, Cursor does nothing.
  40.  
  41. The desk accessory is missing these variables:
  42.    _name_       _reason_
  43.     AppleMenu   menu handles not needed by DAs
  44.     FileMenu     ditto
  45.     EditMenu     ditto
  46.     all other variables with an address of  136 +MD  or greater.
  47.  
  48. Menus
  49.  
  50. The top of the Edit menu and an empty menu available to the DA.
  51.  
  52. The DA's menu structure is a subset of the application's.  The Edit menu pointer is in the same position, but the the empty menu slot of the DA is where the application's File menu pointer would be in the application. See the diagram in the manual that accompanies the discussion of menus.
  53.  
  54. The DA's additional menu is ID number -1.  Create a double variable to hold its handle.  The Edit menu is not numbered by the DA because selections from it are handled as discrete messages.  There is no Edit menu handle since it is owned by the host application rather than the DA.
  55.  
  56. Resources
  57.  
  58. The Pocket Forth DA is composed entirely of resources, as shown in the following list:
  59. type        id          size     description
  60. DICT     -15552   5908    dictionary code
  61. DRVR            26     414    driver code
  62. P4th     -15552       26    signature
  63. WIND    -15552       38    main window
  64.  
  65. Using system software prior to version 7, desk accessories are installed into the system or suitcase files.  During the installation process the ID numbers of resources may change.  Because of this, desk accessories own certain resource ID numbers so that installed DAs can find their resources.  Each DA is allowed to own up to 16 resources of each type.  The numbers owned are derived from a formula:  OwnedID = -16384 + (DRVR ID * 32) + index  where the index is 0 to 15.
  66.  
  67. Pocket Forth programs need not calculate owned resources this way.  An unnamed variable, called MyID (30 +md), has the ID of the first owned resource.  Get additional resource IDs by adding an index of 1 through 15 to the owned ID.
  68.  
  69. To use resources in a program, create and install them into a copy of Pocket Forth.  The first resource of each type should be numbered the same as the DICT resource in the file.  Additional resources of the same type are that number plus one, plus two, etc.  Use ResEdit or an equivalent program to do the resource surgery.  Then, if using an older system, install the DA with the Font/DA Mover.  Your resources will be moved along with Pocket Forth's original ones.
  70.  
  71. This example gets a 'P4th' resource from the desk accessory and displays it:
  72.  
  73. 30 +md @ constant MYID  ( the resource ID   )
  74. : .P4th ( -- ) \ print the P4th resource data
  75.     0 0 2>r      \ room for a result
  76.     ,s P4th 2>r  \ the resource type
  77.     myid >r         \ the resource ID
  78.     ,$ A9A0                            \ _GetResource
  79.     2r>  2dup dl@ 2>r ,$ A884  \ _DrawString
  80.     2>r ,$ A9A3 ;                       \ _ReleaseResource
  81.  
  82. Turnkey
  83.  
  84. The desk accessory has handlers for button down, key down, update and activate events and open, close, idle, cursor, Edit and other menu messages.  Button, activate and update events, idle, cursor and menu messages should be set as described in the events and menu sections of this document or the manual.
  85.  
  86. Key down handlers are unique to the DA version.  The key data is found on the stack when the handler is run.  The low byte of the key data is the ASCII value of the key pressed and the high byte is the key code.  Typically, the key down handler begins with "255 AND" to mask out the key code, leaving the ASCII code on the stack.  Replace the normal key down handler to seal off the interpreter if access to Forth isn't desirable.
  87.  
  88. It is possible to write a key down handler that passes key data through to the interpreter after you are done with it.  This example implements a tab key that emits four spaces, but runs the interpreter normally otherwise.  Get the address of the interpreter's key handle, it's in the handler variable at startup:
  89.  
  90.     32 +MD @ CONSTANT IKEY  ( interpreter's key routine address )
  91.     : W/TABS ( n -- ) ( the interpret routine with tabs )
  92.         255 AND                           \ get ASCII
  93.         DUP 9 = IF                        \ if its a tab key
  94.           DROP SPACE SPACE SPACE SPACE  \ drop code, emit spaces
  95.         ELSE  ,$ 4EEB [ ikey , ]  THEN ; \ jmp ikey(bp)
  96.     ' w/tabs 32 +md !  ( install into key handler )
  97.  
  98. Auto key events are handled by the key down handler.  See below for how to mask out unwanted events if you do not want to handle auto key events as key down events.
  99.  
  100. Open and close handlers work in tandem to create and destroy transient data structures such as handles, menus, windows, etc. The open message happens at the beginning, right after the DA is initialized.  Open message handlers should be written with some limitations in mind.  Particularly, the driver's control routine has not been entered yet, meaning that events and messages cannot be received nor is the parameter block of the DA accessible.  Because of this, the open handler should not try to use events.
  101.  
  102. Memory structures on the heap, created in the open routine or the body of the program, should eventually be destroyed or they will accumulate in the heap.  The usual way to remove heap items is to call the appropriate ROM routine during the close handler. For example, if a handle is created in the open routine, dispose of it in the close routine.
  103.  
  104. The following example produces a turnkey DA.  Don't actually save it because it doesn't do much.
  105.  
  106. ( Handler demo DA )
  107. : MYACT ( flag -- ) IF ." Activated"
  108.                     ELSE ." Deactivated" THEN cr ;
  109. : MYUP ( -- ) ." Updated" cr ;
  110. : MYBUTT ( -- ) ." Mouse button pressed" cr ;
  111. : MYKEY ( n -- ) 255 and emit space ." Key pressed" cr ;
  112. : MYIDLE ( -- ) ." Idle" cr ;
  113. : MYCURS ( -- ) ." Cursor" cr ;
  114. : MYCLOSE ( -- ) beep ;  ( DON'T output to window )
  115. : MYOPEN ( -- ) ." Hi There!" cr ;
  116. : START ( -- ) ( set it all up )
  117.     [ ' myopen literal ]  26 +md !  ( set the open handler )
  118.     [ ' myclose literal ] 22 +md !  ( set the close handler )
  119.     [ ' mycurs literal ]  34 +md !  ( set the cursor handler )
  120.     [ ' myidle literal ]  20 +md !  ( set the idle handler )
  121.     [ ' mykey literal ]   32 +md !  ( set the key down handler )
  122.     [ ' mybutt literal ]  16 +md !  ( set the button handler )
  123.     [ ' myup literal ]    14 +md !  ( set the update handler )
  124.     [ ' myact literal ]   12 +md ! ;  ( set the activate handler )
  125. start ( save )  ( DON'T save unless you really want this )
  126.  
  127. As you can see by running this demo, idle and cursor events overwhelm the other events, so that your DA will be called often enough.  If idle messages or other events are not required, they can be ignored by modifying the Pocket Forth DRVR with ResEdit.
  128.  
  129. The rate the idle handler is called is initially set to run 30 times a second.  This can be changed with ResEdit.  The value in the drvrDelay field represents the time between idle messages in sixtieths of a second.  A value of zero lets the idle routine run as often as possible.  The drvrFlags field of the DRVR's header is normally $6400.  A value of $4400 causes idle messages to be ignored.
  130.  
  131. The drvrEMask field contains the event mask for the DA (see Inside Macintosh, the Event Manager, for details on constructing an event mask.)  Only events that are normally enabled are handled by Pocket Forth, even if the event mask is changed to enable other events. If the event mask is changed to ignore some normally handled events, those events will be ignored.
  132.  
  133. NOTE: The first four fields of the DRVR's header are the only part of the DRVR that should ever be changed.  Modifying the routine addresses will cause an error.
  134.  
  135.  
  136. If you can't find everything you need, or have suggestions, bug reports, questions or comments, write to me:
  137.     Chris Heilman
  138.     [70566,1474] on CompuServe,
  139.     cheilman on American Online,
  140.     heilman@pc.maricopa.edu via internet email or
  141.     PO Box 8345
  142.     Phoenix, AZ 85066-8345 via the US postal service.
  143. My attendance on the commercial services is sporadic, however I usually read my email daily (weekdays) from the internet.
  144.  
  145.